// pages/topicality/gaokao/gkfenshuxian/school.js
//获取应用实例
const app = getApp()
const util = require("../../../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showtk: false,
        showNav: true, // 快捷导航是否展开
        showShare: true, // 显示分享按钮
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            id: options.id ? options.id : '',
            citycode: options.citycode ? options.citycode : '',
        })
        this.getquData(this.data.id, this.data.citycode);
    },

    // 区域分数线
    getquData(id, citycode) {
        let data = {
            action: 'university',
            id: id,
            citycode: citycode,
        };
        util.request('zhuanti.php', data, ).then(res => {
            if (res.data.data.daofen) {
                res.data.data.daofen.content = res.data.data.daofen.content
                    .replace(/<p([\s\w"=\/\.:;]+)((?:(="[^"]+")))/ig, '<p')
                    .replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
                    .replace(/<p([\s\w"=\/\.:;]+)((?:(class="[^"]+")))/ig, '<p')
                    .replace(/<p>/ig, '<p class="p_class">')
                    .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
                    .replace(/<img/gi, '<img style="width:100%;height:auto"')
                    // .replace(/<span>/ig, '<p class="p_class">')
            }
            ks.setNavigationBarTitle({
                title: res.data.data ? res.data.data.title : "高考录取分数线查询",
            })
            if (res.data.data.area) {
                var quList = res.data.data.area.map(item => ({
                    cityname: item,
                    checked: false,
                }));
                quList.unshift({
                    cityname: "全部",
                    checked: true
                })
                this.setData({
                    quList,
                })
            }
            let temparr = [];
            if (res.data.data.list) {
                res.data.data.list.forEach((v, k) => {
                    if (k == 0) {
                        v.showSpread = true;
                    } else {
                        v.showSpread = false;
                    }
                })
            }
            this.setData({
                infoData: res.data.data,
                daofen: res.data.data.daofen,
                listData: res.data.data.list,
            })
        })
    },

    // 区域点击按钮
    quselBtn(e) {
        let quname = e.currentTarget.dataset.name;
        this.data.quList.forEach((v, k) => {
            if (v.cityname == quname) {
                v.checked = true
            } else {
                v.checked = false
            }
        })
        this.setData({
            quList: this.data.quList
        })
        let selContData = [];
        if (quname == "全部") {
            this.setData({
                listData: this.data.infoData.list
            })
        } else {
            selContData = this.data.infoData.list.filter(v => {
                if (v.qu.includes(quname)) {
                    return v;
                }
            })
            this.setData({
                listData: selContData,
            })
        }
        this.data.listData.forEach((v, k) => {
            if (k == 0) {
                v.showSpread = true;
            } else {
                v.showSpread = false;
            }
        })
        this.setData({
            listData: this.data.listData,
        })
    },

    // 是否展开数据
    bindClick(e) {
        let index = e.currentTarget.dataset.index;
        this.data.listData.forEach((v, k) => {
            if (k == index) {
                v.showSpread = !v.showSpread
            }
        })
        this.setData({
            listData: this.data.listData
        })
    },

    // 查看详情点击事件
    seeDetail(e) {
        let id = e.currentTarget.dataset.id;
        let citycode = e.currentTarget.dataset.citycode;
        let url = e.currentTarget.dataset.url;
        let type = e.currentTarget.dataset.type;
        let title = e.currentTarget.dataset.title;
        if (id != 0) {
            ks.navigateTo({
                url: '/pages/article/detail/detail?id=' + id + '&type=' + type + '&city=' + citycode,
            })
        } else {
            this.setData({
                showtk: true
            })
            util.navContact(title, url)
        }
    },

    // 进入客服会话
    contact() {
        this.setData({
            showtk: false,
        })
    },

    // 关闭
    close() {
        this.setData({
            showtk: false,
        })
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        return {
            title: this.data.infoData ? this.data.infoData.title : "高考录取分数线查询",
        }
    },

    // 分享朋友圈
    onShareTimeline: function() {
        return {
            title: this.data.infoData ? this.data.infoData.title : "高考录取分数线查询",
            imageUrl: "http://imgbdb3.bendibao.com/xcx/20207/06/2020706100258_94734.png",
            query: { id: this.data.id },
        }
    },


})